<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css">
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="adminName" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" name="password" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="text" name="phone" id="phone" required  lay-verify="required" placeholder="请输入手机号" autocomplete="off" class="layui-input">
            <button class="layui-btn layui-btn-primary layui-btn-lg" id="gos"  lay-submit="" type="button" lay-filter="">发送验证码</button>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">验证码</label>
        <div class="layui-input-block">
            <input type="text" name="captcha" required  lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <input type="radio" name="state" value="1" title="普通管理员" checked>
        <input type="radio" name="state" value="2" title="超级管理员" >
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>

</form>
</body>
<script src="/lib/layui-v2.5.5/layui.js"></script>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        var $= layui.$  //Jquery对象

        //监听提交
        form.on('submit(formDemo)', function(data){

            $.ajax({
                type:'POST',
                url: '/admin/insertadmin',
                datatype:"json",    //指返回的数据类型
                contentType:"application/json",     //发送到服务器的数据的编码
                data: JSON.stringify(data.field),   //发送到数据库中的数据
                success:function (res) {     //成功后的回调函数  res返回的数据
                    console.log(res)
                    if (res=='ok'){
                        layer.msg("添加成功")
                    }else {
                        layer.alert(res);
                    }
                }
            })


            $("#gos").click(function(){
                console.log($("#phone").val())
                $.ajax({
                    type: 'GET',
                    url: '/index/ssm?phone='+$("#phone").val(),
                    datatype: "json",
                    contentType: "application/json",
                    success: function(res){
                        console.log(res)
                    }
                })
                return false;
            })


/*            $.ajax({
                type:'POST',
                url: '/admin/add',
                datatype:"json",
                contentType:"application/json",
                data: JSON.stringify(data.field),
                success:function (res) {     //成功后的回调函数  res返回的数据
                    console.log(res)
                    if (res.code=='0'){
                        layer.msg("添加成功")
                    }
                }
            });*/
            return false;
        })
    });
</script>
</html>